package com.flashlight;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;

import androidx.appcompat.app.AppCompatActivity;

import com.flashlight.seekbar.VerticalSeekBar;

public class MainActivity extends AppCompatActivity {

    private ImageView ivLight;
    private boolean isLightOn = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ivLight = findViewById(R.id.iv_light);
        VerticalSeekBar seekBar = findViewById(R.id.seekBar);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                setAlpha(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    private void setAlpha(int progress) {
        if (isLightOn) {
            if (progress < 30) {
                ivLight.setImageAlpha(80);
            } else {
                ivLight.setImageAlpha((int) (2.55 * progress));
            }
        } else {
            ivLight.setImageAlpha(80);
        }
    }
}
